﻿#ifndef JCONCURRENT_EXCEPTION_H
#define JCONCURRENT_EXCEPTION_H

#include "jconcurrent_global.h"
#include <exception>

namespace JConcurrent {

class JCONCURRENT_EXPORT Exception : public std::exception
{
public:
    virtual void raise() const;
    virtual Exception *clone() const;
};

class JCONCURRENT_EXPORT UnhandledException : public Exception
{
public:
    void raise() const;
    Exception *clone() const;
};

namespace internal {

class Base;
class JCONCURRENT_EXPORT ExceptionHolder
{
public:
    ExceptionHolder(Exception *exception = 0);
    ExceptionHolder(const ExceptionHolder &other);
    void operator=(const ExceptionHolder &other);
    ~ExceptionHolder();
    Exception *exception() const;
    Base *base;
};

class JCONCURRENT_EXPORT ExceptionStore
{
public:
    void setException(const Exception &e);
    bool hasException() const;
    ExceptionHolder exception();
    void throwPossibleException();
    bool hasThrown() const;
    ExceptionHolder exceptionHolder;
};

} // namespace internal

} // namespace JConcurrent

#endif  // JCONCURRENT_EXCEPTION_H
